﻿//
// Copyright (c) 2010
// by Chris Paterra
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
//

using System;
using DotNetNuke.ContentLibrary.Demo.Components.Models;
using DotNetNuke.ContentLibrary.Demo.Components.Presenters;
using DotNetNuke.ContentLibrary.Demo.Components.Views;
using DotNetNuke.Web.Mvp;
using WebFormsMvp;

namespace DotNetNuke.ContentLibrary.Demo
{
	[PresenterBinding(typeof(FavoriteListDemoPresenter))]
	public partial class FavoriteListDemo : ModuleView<FavoriteListDemoModel>, IFavoriteListDemoView {

		#region Events

		/// <summary>
		/// 
		/// </summary>
		/// <param name="e"></param>
		protected override void OnInit(EventArgs e) {
			base.OnInit(e);
			AutoDataBind = false;
		}

		/// <summary>
		/// This event fires when a combobox has its selected index changed.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		protected void ComboBoxIndexChanged(object sender, Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs e)
		{
			SetProps();
			dclFavoritesList.Reset();
		}

		/// <summary>
		/// This event fires each time the page is loaded. 
		/// </summary>
		public void Refresh()
		{
			if (Page.IsPostBack) return;
			BindDropDowns();
			SetProps();
		}

		#endregion

		#region Private Methods

		/// <summary>
		/// Binds a list of available content types to the combobox.
		/// </summary>
		private void BindDropDowns() {
			rcbContentFilter.Items.Clear();
			rcbContentFilter.Items.Add(new Telerik.Web.UI.RadComboBoxItem(Services.Localization.Localization.GetString("None", LocalResourceFile), "0"));

			foreach (var objCType in Model.ColContentTypes)
			{
				rcbContentFilter.Items.Add(new Telerik.Web.UI.RadComboBoxItem(objCType.ContentType, objCType.ContentTypeId.ToString()));
			}
		}

		/// <summary>
		/// Set the DCL control properties.
		/// </summary>
		private void SetProps()
		{
			dclFavoritesList.PortalID = ModuleContext.PortalId;
			dclFavoritesList.CurrentUserID = Model.CurrentUserID;
			// Optional
			dclFavoritesList.ContentTypeID = Convert.ToInt32(rcbContentFilter.SelectedValue);
			dclFavoritesList.PageSize = 2;
			// PageSize selector is hidden because of a problem showing the pager when here. 
			//dclFavoritesList.PageSize = Convert.ToInt32(rcbPageSize.SelectedValue);
		}

		#endregion

	}
}